//课程卡播放窗口：状态
//const SET_COURSE_CARD_ID ='cards/SET_COURSE_CARD_ID';
const ACTIVATE_CARDS ='cards/ACTIVATE_CARDS';
const VIEW_CARDS = 'cards/VIEW_CARDS';
const CLOSE_CARDS ='cards/CLOSE_CARDS';
const NEXT_STEP = 'cards/NEXT_STEP';
const PREV_STEP ='cards/PREV_STEP';
const SHRINK_EXPAND_CARDS ='cards/SHRINK_EXPAND_CARDS';
const DRAG_CARD = 'cards/DRAG_CARD';
const START_DRAG ='cards/START_DRAG';
const END_DRAG = 'cards/END_DRAG';

const initialState = {
//    lessonCardId: 0,//课程卡ID
    content: null,

    visible: false,//是否显示
    step: 0,        //显示第几部分
    x: 0,           //显示位置
    y: 0,           //显示位置
    expanded: true,//展开状态
    dragging: false
};

const reducer = function (state, action) {
    if (typeof state === 'undefined') state = initialState;
    switch (action.type) {
    // case SET_COURSE_CARD_ID://设置课程卡ID
    //     return {...state, lessonCardId: action.lessonCardId};
    case ACTIVATE_CARDS://激活课程卡，并显示
        return {...state, content: action.content, visible: true};
    case VIEW_CARDS://显示课程卡
        return {...state, visible: true};
    case CLOSE_CARDS://关闭课程卡
        return {...state, visible: false};
    case SHRINK_EXPAND_CARDS://展开与收起
        return {...state, expanded: !state.expanded};
    case NEXT_STEP://下一张课程卡
        if (state.activeDeckId !== null) {
            return {...state, step: state.step + 1};
        }
        return state;
    case PREV_STEP://上一张课程卡
        if (state.activeDeckId !== null && state.step > 0) {
            return {...state, step: state.step - 1};
        }
        return state;
    case DRAG_CARD://拖动
        return {...state, x: action.x, y: action.y};
    case START_DRAG:
        return {...state, dragging: true};
    case END_DRAG:
        return {...state, dragging: false};
    default:
        return state;
    }
};

//const setLessonCardId = function (lessonCardId) {return {type: SET_COURSE_CARD_ID,lessonCardId};};
const activateCourseCards = function (content) {return {type: ACTIVATE_CARDS,content};};
const viewCards = function () {return {type: VIEW_CARDS};};
const closeCards = function () {return {type: CLOSE_CARDS};};
const shrinkExpandCards = function () {return {type: SHRINK_EXPAND_CARDS};};
const nextStep = function () {return {type: NEXT_STEP};};
const prevStep = function () {return {type: PREV_STEP};};
const dragCard = function (x, y) {return {type: DRAG_CARD, x, y};};
const startDrag = function () {return {type: START_DRAG};};
const endDrag = function () {return {type: END_DRAG};};

export {
    reducer as default,
    initialState as cardsInitialState,
//    setLessonCardId,
    activateCourseCards,
    viewCards,
    closeCards,
    shrinkExpandCards,
    nextStep,
    prevStep,
    dragCard,
    startDrag,
    endDrag
};
